package com.example.smartcity_40.Outpatient;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.widget.ViewPager2;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.example.smartcity_40.Outpatient.apter.MediclistApter;
import com.example.smartcity_40.Outpatient.bean.HospitalBannerBean;
import com.example.smartcity_40.Outpatient.bean.MediclistBean;
import com.example.smartcity_40.R;
import com.example.smartcity_40.tool.Tool;

import java.util.ArrayList;

import kotlin.Unit;
import kotlin.jvm.functions.Function1;

public class OutpatientActivity extends AppCompatActivity {

    private OutpatientActivity context;
    private Tool tool;
    private ViewPager2 banner;
    private RecyclerView mediclist;
    private MediclistApter mediclistApter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_outpatient);
        context = this;
        initview();
        bannermethod();
        mediclistmethod();
    }

    private void mediclistmethod() {
        tool.send("/prod-api/api/hospital/hospital/list",
                Tool.GET,
                null,
                false,
                MediclistBean.class, new Function1<MediclistBean, Unit>() {
                    @Override
                    public Unit invoke(MediclistBean mediclistBean) {
                        mediclistApter.setDate(mediclistBean.getRows());
                        mediclist.setAdapter(mediclistApter);
                        mediclist.setLayoutManager(new LinearLayoutManager(context));
                        return null;
                    }
                });
    }

    private void bannermethod() {
        tool.send("/prod-api/api/hospital/banner/list",
                Tool.GET,
                null,
                false,
                HospitalBannerBean.class, new Function1<HospitalBannerBean, Unit>() {
                    @Override
                    public Unit invoke(HospitalBannerBean hospitalBannerBean) {
                        ArrayList<String> imglist = new ArrayList<>();
                        for (HospitalBannerBean.DataBean datum : hospitalBannerBean.getData()) {
                            imglist.add(datum.getImgUrl());
                        }
                        tool.setBanner(banner,imglist);
                        return null;
                    }
                });
    }

    private void initview() {
        ImageView back = findViewById(R.id.back);
        mediclist = findViewById(R.id.Mediclist);
        banner = findViewById(R.id.banner);
        tool = new Tool(context);
        mediclistApter = new MediclistApter(context);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.finish();
            }
        });
    }
}